<!--
 * @Author: 梁 卓
 * @Version: V1.0.0
 * @Date: 2024-02-24 10:08:25
 * @LastEditors: 梁 卓
 * @LastEditTime: 2024-02-26 12:10:23
 * @FilePath: bookinfoedit.html
 * Copyright 2024 Marvin, All Rights Reserved. 
 * 2024-02-24 10:08:25
 * @Description: 
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书信息编辑</title>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <script src="../../demo/demo.css" type="text/javascript"></script>
    <style type="text/css">
    html, body
    {        
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    .asLabel .mini-textbox-border,
    .asLabel .mini-textbox-input,
    .asLabel .mini-buttonedit-border,
    .asLabel .mini-buttonedit-input,
    .asLabel .mini-textboxlist-border
    {
        border:0;background:none;cursor:default;
    }
    .asLabel .mini-buttonedit-buttons,
    .asLabel .mini-buttonedit-button,
    .asLabel .mini-textboxlist-close
    {
        display:none;
    }
    .asLabel .mini-textboxlist-item
    {
        padding-right:8px;
    }
    </style>
</head>
<body>
  <form id="bookinfoform" method="post">
    <input name="bookId" class="mini-hidden" />
    <fieldset style="border:solid 1px #aaa;padding:3px;">
        <legend >图书信息编辑</legend>
        <div style="padding:5px;">
    <table>
        <tr>
            <td align="right">图书名称：</td>
            <td >    
                <input name="bookName" class="mini-textbox" emptyText="请输入图书名称"
                 required="true" requiredErrorMessage="图书名称不能为空！" />
            </td>

            <td align="right">出版社：</td>
            <td >    
                <input name="publisher" class="mini-textbox" emptyText="请输入图书出版社"
                required="true" requiredErrorMessage="出版社名称不能为空！"/>
            </td>
        </tr>

        <tr>
            <td align="right">作者：</td>
            <td >    
                <input name="author" class="mini-textbox" emptyText="请输入图书作者"
                required="true" requiredErrorMessage="作者名称不能为空！"/>
            </td>

            <td align="right">图书类别：</td>
            <td >   <!-- 只读 readOnly + css 样式 asLabel-->
                <input id="booktype" name="bookType" class="mini-combobox asLabel" allowInput="true" 
                showNullItem="true" nullItemText="请选择类别-"  renderer="onBookTypeRenderer"
                url="../../data/booktype.txt" textField="text" valueField="id" 
                required="true" requiredErrorMessage="图书类别不能为空！" readOnly />
            </td>
        </tr>

        <tr>
            <td align="right">剩余数量：</td>
            <td>
                <input name="remain" class="mini-spinner" 
                format="#,0" increment=1 minValue="0" maxValue="200" 
                required="true" requiredErrorMessage="剩余数量不能为空！"/>
            </td>
        </tr>   
    </table>            
        </div>
            </fieldset>
            <div style="text-align:center;padding:10px;">               
                <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
                <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>


    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("bookinfoform");
        // 父子组件传值
        function SetData(data) {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            $.ajax({
                url:'/bookmanagement/bookinfolistaction?method=queryBookInfoByID&bookId='+data.bookId,
                type:"get",
                dataType: 'json',
                cache: false,
                success: function(res) {
                    var o = mini.decode(res)
                    form.setData(o)
                    form.setChanged(false)
                },
                error: function(xhr, status, error) {
                    // 在这里处理错误情况
                    console.error('请求失败：' + error);
                }
            })
        }

        function SaveData() {
            var o = form.getData();
            form.validate();
            if (form.isValid() == false) {
                mini.alert("缺少填写某些内容", '错误')
                return;
            }
            var json = mini.encode(o);
            mini.confirm("确定要修改吗？", '提示', function() {
                updataAjax(json)
            })
        }
        // 更新请求
        function updataAjax(json) {
            $.ajax({
                url:'/bookmanagement/bookinfolistaction?method=updateBookinfo',
                type: 'post',
                data: { data: json },
                cache: false,
                success: function(res) {
                    mini.alert(res, '提示',function() {
                        CloseWindow("save");
                    })
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            })
        }

        // 确认按钮
        function onOk(e) {
            SaveData();
        }
        // 取消按钮
        function onCancel(e) {
            CloseWindow('close') 
        }
        // 关闭窗口
        function CloseWindow(action) {
            if (action === "close" && form.isChanged()) {
                console.log('11')
                mini.confirm('数据被修改了，是否先保存？', '提示', function(callTxt) {
                    // 确定 ok, 取消 cancel ，修改数据且点击了取消按钮则提示保存
                    if (callTxt === 'ok') {
                        onOk()
                    } else {
                        window.close();
                    }
                })
            } else {
                window.CloseOwnerWindow(action)
            }
            
        }
        
    </script>
</body>
</html>